package com.vast.ui.component.providers;

import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;

import com.vast.ui.component.models.Led;
import com.vast.ui.ledpanel.Activator;
public class LedLabelProvider extends LabelProvider implements
ITableLabelProvider {
	private Display display;
	private Image green = Activator.getDefault().getImageRegistry().get("LED_GREEN");
	private Image red   = Activator.getDefault().getImageRegistry().get("LED_RED");
	
	
	public LedLabelProvider(Display display) {
		this.display  = display;
		/*
		colorRegistry = new ColorRegistry();
		pallet = new Color[256];
		
		int r = 0;
		int g = 0;
		int b = 0;
		for(int i = 0; i < 256; i++) {
			if(i == 0) {
				r = 255;
				g = 255;
				b = 255;
			} else if(i < 64) {
				r = 255 - (i * 4);
				g = 255;
				b = 0;
			} else if (i < 128) {
				r = 0;
				g = 255 - ((i - 64) * 4);
				b = 255;
			} else if (i < 192) {
				r = 128;
				g = 128;
				b = 255 - ((i - 128) * 4);
			} else {
				r = 255 - ((i - 192) * 4);
				g = 32;
				b = 32;
			}
			pallet[i] = new Color(display, r, g, b);
		}

		// Generate ColoerRegister to set RGB value of pallet[]
		colorRegistry = new ColorRegistry();
		for (Color color : pallet) {
			colorRegistry.put(color.toString(), color.getRGB());
		}
		
		// Generate ImageRegistry
		imageRegistry = new ImageRegistry();
		*/
	}
	
	private Image getLedImage(final Led led) {
		return null;
	}
	
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		//if (element instanceof Led) {
		//	Led led = (Led) element;
		//	if (columnIndex == 17) {
		//		return getLedImage(led);
		//	}
		//}
		if(element instanceof Led) {
			Led led = (Led)element;
			if(led.isChecked(columnIndex - 1)){
				return red;
			}
			return green;
		}
		return null;
	}

	public String getColumnText(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		/*
		Led led = (Led) element;
		// 
		if(columnIndex == 0) {
			return Integer.toString(led.no);
		} else if (columnIndex == 1) {
			return null;
		} else if (columnIndex == 2) {
			return Integer.toHexString(led.value & 0xFFFFFFFF);
		}
		*/
		return null;
	}

	public Color getBackground(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		/*
		if (element instanceof Led && columnIndex == 1) {
			Led led = (Led)element;
		    int r = (led.value >> 16) & 0xFF;
			int g = (led.value >> 8) & 0xFF;
			int b = led.value & 0xFF;
			Color fullColor = new Color(display, r, g, b);;
			return fullColor;
		}
		*/
		return null;
	}

	public Color getForeground(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}

}
